package com.bcu.cn.onlineexamsystem.studentmanage.mapper;

import com.bcu.cn.onlineexamsystem.studentmanage.entity.ExamDetailForPdf;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.util.List;

@Mapper
public interface StudentExamPdfMapper {
    @Select("SELECT e.exam_name, c.course_name, e.exam_type, u.real_name AS teacher_name, cl.class_name, e.start_time, e.end_time, e.duration, e.total_score " +
            "FROM student_exams se " +
            "JOIN exams e ON se.exam_id = e.exam_id " +
            "JOIN courses c ON e.course_id = c.course_id " +
            "JOIN users u ON e.teacher_id = u.user_id " +
            "LEFT JOIN exam_classes ec ON e.exam_id = ec.exam_id " +
            "LEFT JOIN classes cl ON ec.class_id = cl.class_id " +
            "WHERE se.record_id = #{recordId} AND se.student_id = #{studentId} LIMIT 1")
    ExamDetailForPdf getExamDetailForPdf(@Param("recordId") Long recordId, @Param("studentId") String studentId);

    @Select("SELECT q.type, q.content, q.score, q.answer AS std_answer, sa.answer AS student_answer, sa.score AS student_score, sa.teacher_comment " +
            "FROM student_answers sa " +
            "JOIN questions q ON sa.question_id = q.question_id " +
            "WHERE sa.record_id = #{recordId}")
    List<ExamDetailForPdf.QuestionDetailForPdf> getQuestionDetailsForPdf(@Param("recordId") Long recordId);
} 